#include"Sock.hpp"
#include"Task.hpp"
#include"ThreadPool.hpp"
void Usage(string proc)
{
  cout <<"Usage\n\t" << proc <<" server_port" << endl;
  exit(1);
}
int main(int argc,char* argv[])
{
  if(argc != 2)
  {
    Usage(argv[0]);
  }
  uint16_t port = atoi(argv[1]);
  int listen_sock = Sock::Socket();
  cout <<"Socket Success !"<<endl;
  Sock::Bind(listen_sock,port);
  cout <<"Bind Success !" << endl;
  Sock::Listen(listen_sock);
  cout <<"Listen Success !" << endl;

  ThreadPool<Task>* tp = ThreadPool<Task>::GetInstance();
  for(;;)
  {
    int new_sock = Sock::Accept(listen_sock);
    if(new_sock <= 0)
      continue;
    //构建一个任务,然后插入到线程池的任务队列当中 
    Task t(new_sock);
    tp->push(t);
  }
  return 0;
}
